package org.chuanyang.mm;

import java.util.Calendar;

import org.chuanyang.mm.utils.HandleDateAndTime;

import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.Context;
import android.widget.DatePicker;

public class EditDateDialog {

	private HandleDateAndTime dt;
	private Context context;
	private Operate operate;

	public EditDateDialog(Context context) {
		this.context = context;
		this.operate = (Operate) context;
		init();
	}

	private void init() {
		dt = new HandleDateAndTime();
	}

	public void createDateDialog() {

		OnDateSetListener callBack = new OnDateSetListener() {

			@Override
			public void onDateSet(DatePicker view, int year, int monthOfYear,
					int dayOfMonth) {
				dt.calendar.set(Calendar.YEAR, year);
				dt.calendar.set(Calendar.MONTH, monthOfYear);
				dt.calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
				operate.refreshDate(dt.getSetDate());
			}
		};

		new DatePickerDialog(context, callBack, dt.calendar.get(Calendar.YEAR),
				dt.calendar.get(Calendar.MONTH),
				dt.calendar.get(Calendar.DAY_OF_MONTH)).show();
	}
}
